package com.shlh.saas.mapper.canton.exhibitor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shlh.saas.entity.canton.exhibitor.CantonFairExhibitor135;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 第135届广交会展商数据访问接口
 */
@Mapper
public interface CantonFairExhibitor135Mapper extends BaseMapper<CantonFairExhibitor135> {
    
    /**
     * 使用自定义 SQL 查询，避免 MyBatis 自动生成包含不存在字段的 SQL
     */
    @Select("SELECT id, period, category, booth_number, company_name, principal_name, principal_position, principal_mobile, principal_phone, contact_person, phone, fax, website, contact_address, postal_code, `session`, main_products, company_scale, registered_capital, company_type, business_scope_details, company_profile, province_city, establishment_year, email, mobile, recent_exhibition_history, company_identifier, innovation_award, cf_award, multiple_exhibition, brand_exhibitor, old_brand, rural_exhibitor, new_exhibitor, specialized_new, green_award, customs_certificate, high_tech, city FROM canton_fair_exhibitors_135 ${ew.customSqlSegment}")
    List<CantonFairExhibitor135> selectListWithCustomSql(@Param("ew") LambdaQueryWrapper<CantonFairExhibitor135> wrapper);
    
    /**
     * 使用自定义 SQL 查询分页数据，避免 MyBatis 自动生成包含不存在字段的 SQL
     */
    @Select("SELECT id, period, category, booth_number, company_name, principal_name, principal_position, principal_mobile, principal_phone, contact_person, phone, fax, website, contact_address, postal_code, `session`, main_products, company_scale, registered_capital, company_type, business_scope_details, company_profile, province_city, establishment_year, email, mobile, recent_exhibition_history, company_identifier, innovation_award, cf_award, multiple_exhibition, brand_exhibitor, old_brand, rural_exhibitor, new_exhibitor, specialized_new, green_award, customs_certificate, high_tech, city FROM canton_fair_exhibitors_135 ${ew.customSqlSegment}")
    Page<CantonFairExhibitor135> selectPageWithCustomSql(Page<CantonFairExhibitor135> page, @Param("ew") LambdaQueryWrapper<CantonFairExhibitor135> wrapper);

    /**
     * 使用自定义 SQL 查询计数，避免 MyBatis 自动生成包含不存在字段的 SQL
     */
    @Select("SELECT COUNT(*) FROM canton_fair_exhibitors_135 ${ew.customSqlSegment}")
    Long selectCountWithCustomSql(@Param("ew") LambdaQueryWrapper<CantonFairExhibitor135> wrapper);

    // 重构后新增的方法

    /**
     * 分页查询所有数据
     */
    @Select("SELECT id, period, category, booth_number, company_name, principal_name, principal_position, principal_mobile, principal_phone, contact_person, phone, fax, website, contact_address, postal_code, `session`, main_products, company_scale, registered_capital, company_type, business_scope_details, company_profile, province_city, establishment_year, email, mobile, recent_exhibition_history, company_identifier, innovation_award, cf_award, multiple_exhibition, brand_exhibitor, old_brand, rural_exhibitor, new_exhibitor, specialized_new, green_award, customs_certificate, high_tech, city FROM canton_fair_exhibitors_135 ORDER BY id DESC LIMIT #{limit} OFFSET #{offset}")
    List<CantonFairExhibitor135> selectAllWithPage(@Param("offset") int offset, @Param("limit") int limit);

    /**
     * 根据关键词搜索（分页）
     */
    @Select("SELECT id, period, category, booth_number, company_name, principal_name, principal_position, principal_mobile, principal_phone, contact_person, phone, fax, website, contact_address, postal_code, `session`, main_products, company_scale, registered_capital, company_type, business_scope_details, company_profile, province_city, establishment_year, email, mobile, recent_exhibition_history, company_identifier, innovation_award, cf_award, multiple_exhibition, brand_exhibitor, old_brand, rural_exhibitor, new_exhibitor, specialized_new, green_award, customs_certificate, high_tech, city FROM canton_fair_exhibitors_135 WHERE ${condition} ORDER BY id DESC LIMIT #{limit} OFFSET #{offset}")
    List<CantonFairExhibitor135> searchByKeywordWithPage(@Param("condition") String condition, @Param("offset") int offset, @Param("limit") int limit);

    /**
     * 根据筛选条件搜索（分页）
     */
    @Select("SELECT id, period, category, booth_number, company_name, principal_name, principal_position, principal_mobile, principal_phone, contact_person, phone, fax, website, contact_address, postal_code, `session`, main_products, company_scale, registered_capital, company_type, business_scope_details, company_profile, province_city, establishment_year, email, mobile, recent_exhibition_history, company_identifier, innovation_award, cf_award, multiple_exhibition, brand_exhibitor, old_brand, rural_exhibitor, new_exhibitor, specialized_new, green_award, customs_certificate, high_tech, city FROM canton_fair_exhibitors_135 WHERE ${condition} ORDER BY id DESC LIMIT #{limit} OFFSET #{offset}")
    List<CantonFairExhibitor135> searchWithFiltersAndPage(@Param("condition") String condition, @Param("offset") int offset, @Param("limit") int limit);

    /**
     * 根据关键词统计数量
     */
    @Select("SELECT COUNT(*) FROM canton_fair_exhibitors_135 WHERE ${condition}")
    long countByKeyword(@Param("condition") String condition);

    /**
     * 根据筛选条件统计数量
     */
    @Select("SELECT COUNT(*) FROM canton_fair_exhibitors_135 WHERE ${condition}")
    long countWithFilters(@Param("condition") String condition);
}